package com.yjy.mybase.http;

import com.google.gson.JsonSyntaxException;
import com.yjy.mybase.model.BaseBean;
import com.yjy.mybase.utils.ToastUtils;

public abstract class CustomCallback<T extends BaseBean> extends ICallback<T> {
    @Override
    public void onSuccess(T data) {
        try {
            if(data.isSuccess()){
                success((T)data);
            }else {
                ToastUtils.show(data.getMessage());
                onFail(data.getCode(),data.getMessage());
            }
        }catch (Exception e){

            this.onFail(500,"服务器异常");
        }


    }

    @Override
    public void onFail(int errCode, String errMsg) {
        ToastUtils.show(errCode +"---"+ errMsg);
        try {

        }catch (JsonSyntaxException e){

        }
    }

    public abstract void success(T t);

}
